package com.itheima.mall.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.mall.mapper.SubjectMapper;
import com.itheima.mall.pojo.Subject;
import com.itheima.mall.service.CmsSubjectService;
import com.itheima.mall.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CmsSubjectServiceImpl implements CmsSubjectService {

    @Autowired
    private SubjectMapper subjectMapper;
    @Override
    public PageResult subjectList(String keyword, Integer pageNum, Integer pageSize) {
        LambdaQueryWrapper<Subject> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(keyword != null , Subject::getCategoryName , keyword);
        Page<Subject> page = new Page<>(pageNum, pageSize);

        Page<Subject> pageInfo = subjectMapper.selectPage(page, lambdaQueryWrapper);
        return new PageResult(pageNum , pageSize ,(int) pageInfo.getTotal() , pageInfo.getRecords());
    }
    //获取全部商品专题
    @Override
    public List<Subject> subjectListAll() {
        LambdaQueryWrapper<Subject> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        List<Subject> list = subjectMapper.selectList(lambdaQueryWrapper);
        return list;
    }
}
